package com.software.seakdream.service;

import com.software.seakdream.entity.SleepInfo;
import com.software.seakdream.repository.SleepInfoRepository;
import java.util.List;
import org.apache.ibatis.javassist.Loader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Service
public class SleepInfoServiceImpl implements SleepInfoService{

    @Autowired
    private SleepInfoRepository sleepInfoRepository;



    @Override
    public int createSleepInfo(SleepInfo sleepInfo) {
        return sleepInfoRepository.createSleepInfo(sleepInfo);
    }

    @Override
    public SleepInfo findSleepInfoById(String sleepId) {
        SleepInfo sleepInfo = sleepInfoRepository.findSleepInfoById(sleepId);
        return sleepInfo;
    }

    @Override
    public SleepInfo findLastSleepInfo(String userId) {
        List<SleepInfo> sleepInfos = sleepInfoRepository.findSleepInfoUseLimit(userId,0,1);
        if(sleepInfos.size()==0){
            return null;
        }else{
            return sleepInfos.get(0);
        }
    }

    @Override
    public List<SleepInfo> findSleepInfoUsePage(String userId, int page, int pageSize) {
        return sleepInfoRepository.findSleepInfoUseLimit(userId,(page-1)*pageSize,pageSize);
    }

    @Override
    public List<SleepInfo> findSleepInfoInRange(String userId, String left, String right) {
        return sleepInfoRepository.findSleepInfoInRange(userId,left,right);
    }
}
